package cn.tedu.admin.content.service.impl;

import cn.tedu.admin.content.dao.persist.mapper.CategoryMapper;
import cn.tedu.admin.content.dao.persist.mapper.repository.CategoryRepository;
import cn.tedu.admin.content.pojo.bo.CategoryBO;
import cn.tedu.admin.content.pojo.param.CategoryAddParam;
import cn.tedu.admin.content.pojo.po.CategoryPO;
import cn.tedu.admin.content.service.CategoryService;
import cn.tedu.admin.content.service.OtherService;
import cn.tedu.admin.content.util.CommonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class OtherServiceImpl implements OtherService {

    @Autowired
    private CategoryMapper categoryMapper;
    
    @Autowired
    private CategoryRepository categoryRepository;

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private CommonUtils commonUtils;

    @Override
    public List<CategoryBO> listCategory() {
        //从Repository查询数据,Service并不关心Repository
        // 是怎么实现的
        categoryMapper.list();
        List<CategoryPO> list = categoryRepository.list();
        //把PO转换为VO;
        List<CategoryBO> result = new ArrayList<>();
        for (CategoryPO categoryPO : list) {
            CategoryBO categoryBO = new CategoryBO();
            BeanUtils.copyProperties(categoryPO,categoryBO);
            result.add(categoryBO);
        }
        return result;
    }

    @Override
    public void otherMethod(CategoryAddParam categoryAddParam) {
        categoryService.addCategory(categoryAddParam);
    }

}
